<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Order
 *
 * @property int $id
 * @property string|null $contract_no
 * @property string|null $renewal_contract_number
 * @property int|null $user_id
 * @property int|null $worker_id
 * @property int|null $record_worker_id
 * @property int|null $product_id
 * @property int|null $branch_id
 * @property int|null $bank_card_id
 * @property int|null $families_id
 * @property int|null $order_status
 * @property int|null $is_first
 * @property int $audit_step
 * @property string|null $order_no
 * @property string|null $is_first_instance
 * @property int|null $investment_way
 * @property float|null $results_rate
 * @property float|null $order_money
 * @property string|null $results_money
 * @property string|null $course_money
 * @property string|null $remark
 * @property Carbon|null $contract_end_date
 * @property Carbon|null $sign_time
 * @property Carbon|null $valid_time
 * @property Carbon|null $account_time
 * @property string|null $wealth_manage_id
 * @property string|null $group_manage_id
 * @property string|null $sales_manage_id
 * @property string|null $department_manage_id
 * @property string|null $regional_manage_id
 * @property string|null $vice_president_id
 * @property string|null $president_id
 * @property Carbon|null $update_time
 * @property Carbon|null $create_time
 * @property int|null $id_type
 * @property int|null $old_id
 * @property int|null $sms_status
 * @property int|null $order_id
 * @property int|null $template_id
 * @property int|null $fdd_sign_status
 * @property int|null $contract_file
 *
 * @property BankCard|null $bank_card
 * @property Branch|null $branch
 * @property ContractModel|null $contract_model
 * @property Order|null $order
 * @property Product|null $product
 * @property User|null $user
 * @property Worker|null $worker
 * @property WorkingFamily|null $working_family
 * @property Collection|FamiliesMoneyRecord[] $families_money_records
 * @property Collection|Image[] $images
 * @property Collection|InterestRecord[] $interest_records
 * @property Collection|MassageChangeRecord[] $massage_change_records
 * @property Collection|Order[] $orders
 * @property Collection|OrderRecord[] $order_records
 * @property Collection|TlPayList[] $tl_pay_lists
 *
 * @package App\Models
 */
class Order extends Model
{
    protected $table = 'order';

    protected $casts = [
        'user_id' => 'int',
        'worker_id' => 'int',
        'record_worker_id' => 'int',
        'product_id' => 'int',
        'branch_id' => 'int',
        'bank_card_id' => 'int',
        'families_id' => 'int',
        'order_status' => 'int',
        'is_first' => 'int',
        'audit_step' => 'int',
        'investment_way' => 'int',
        'results_rate' => 'float',
        'order_money' => 'float',
        'id_type' => 'int',
        'old_id' => 'int',
        'sms_status' => 'int',
        'order_id' => 'int',
        'template_id' => 'int',
        'fdd_sign_status' => 'int',
        'contract_file' => 'int'
    ];

    protected $dates = [
        'contract_end_date',
        'sign_time',
        'valid_time',
        'account_time'
    ];

    protected $fillable = [
        'contract_no',
        'renewal_contract_number',
        'user_id',
        'worker_id',
        'record_worker_id',
        'product_id',
        'branch_id',
        'bank_card_id',
        'families_id',
        'order_status',
        'is_first',
        'audit_step',
        'order_no',
        'is_first_instance',
        'investment_way',
        'results_rate',
        'order_money',
        'results_money',
        'course_money',
        'remark',
        'contract_end_date',
        'sign_time',
        'valid_time',
        'account_time',
        'wealth_manage_id',
        'group_manage_id',
        'sales_manage_id',
        'department_manage_id',
        'regional_manage_id',
        'vice_president_id',
        'president_id',
        'id_type',
        'old_id',
        'sms_status',
        'order_id',
        'template_id',
        'fdd_sign_status',
        'contract_file'
    ];

    public function bank_card()
    {
        return $this->belongsTo(BankCard::class);
    }

    public function branch()
    {
        return $this->belongsTo(Branch::class);
    }

    public function contract_model()
    {
        return $this->belongsTo(ContractModel::class, 'template_id');
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function worker()
    {
        return $this->belongsTo(Worker::class, 'worker_id');
    }

    public function record_worker()
    {
        return $this->belongsTo(Worker::class, 'record_worker_id');
    }

    public function working_family()
    {
        return $this->belongsTo(WorkingFamily::class, 'families_id');
    }

    public function families_money_records()
    {
        return $this->hasMany(FamiliesMoneyRecord::class);
    }


    public function images()
    {
        return $this->hasMany(Image::class);
    }

    public function interest_records()
    {
        return $this->hasMany(InterestRecord::class);
    }

    public function order_records()
    {
        return $this->hasMany(OrderRecord::class);
    }

    public function fdd_records()
    {
        return $this->hasMany(FddRecord::class);
    }

    public function massage_change_records()
    {
        return $this->hasMany(MassageChangeRecord::class);
    }

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function orders()
    {
        return $this->hasMany(Order::class);
    }


    public function tl_pay_lists()
    {
        return $this->hasMany(TlPayList::class);
    }
}
